<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <style>
        #div1{
            border: 1px solid #000;
            width: 300px;
            height: 200px;
            display: none;
        }
        #div1 button{
            width: 60px;
            height: 30px;
        }
    </style>
    <script>
        var oDiv = null;
        var aBtn = null;
        var aDiv = null;
        window.onload =function () {
            oDiv = document.querySelector("#div1");
            aBtn = oDiv.querySelectorAll("button");
            aDiv = oDiv.querySelectorAll("div");
            //把onload中不是赋值的语句放到单独函数中
            init();
        }
        function init() {
            for(var i=0;i<aBtn.length;i++){
                aBtn[i].index = i;
                aBtn[i].onclick = change;
            }
        }
        //不要出现函数嵌套函数的情况
        function change() {
            for(var i=0;i<aBtn.length;i++){
                aBtn[i].style.backgroundColor = "";
                aDiv[i].style.display = "none";
            }
            this.style.backgroundColor = "pink";
            aDiv[this.index].style.display = "block";
        }
    </script>
</head>
<body>

<div id="div1">
    <button style="background-color: pink;">1</button>
    <button>2</button>
    <button>3</button>
    <div style="display: block">内容1</div>
    <div>内容2</div>
    <div>内容3</div>
</div>

</body>
</html>